package com.eshop.we.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.eshop.we.book.dto.BookDto;
import com.eshop.we.book.entity.Book;
import com.eshop.we.business.BookBusiness;
import com.eshop.we.result.Result;
import com.eshop.we.user.dto.UserInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController extends BaseController {

    @Autowired
    BookBusiness bookBusiness;

    @GetMapping("/getbookpage")
    public Result getBookPage(@RequestParam(required = false)String name,@RequestParam(required = false)String bookName,
                              @RequestParam(required = false)String startDate,@RequestParam(required = false)String endDate,
                              @RequestParam(required = false,defaultValue = "1")Integer pageNum,@RequestParam(required = false,defaultValue = "20")Integer pageSize){
        Page<BookDto> page=new Page<>(pageNum,pageSize);
        page=bookBusiness.selectBookPage(page,name,bookName,startDate,endDate);
        return Result.success(page);
    }

    @PutMapping("/updatebookstatus")
    public Result updateBookStatus(@RequestParam(required = true) Integer bookId,@RequestParam(required = true)Integer status){
        Book book=new Book();
        book.setId(bookId);
        book.setStatus(status);
       return Result.success(bookBusiness.updateById(book));
    }

    @GetMapping("/getbookinfo")
    public Result getBookInfo(@RequestParam(required = true)Integer bookId){
       Book book=new Book();
       book.setId(bookId);
       return Result.success(bookBusiness.selectById(book));
    }
}
